<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <script type="text/javascript" src="${ctx}/js/jquery.js"></script>
    <script type="text/javascript" src="${ctx}/js/sapar.js"></script>
    <script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
    <script type="text/javascript" src="${ctx}/js/mask.js"></script>
    <script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <script type="text/javascript" src="${ctx}/assets/laydate/laydate.js"></script>
    <script type="text/javascript" src="${ctx}/js/LodopFuncs.js"></script>
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
    </object>
    <title>配包审核</title>
    <style type="text/css">
        th, td {
            text-align: center;
        }
    </style>
</head>

<body>
<div id="left">
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>关包</h2>
            </div>
            <div class="subfiled-content">


                <!--表格开始-->
                <div id="table_left" class="table">

                    <!--表格具体内容-->
                    <form action="" id="guanbaoform">
                        <div class="table-box">
                            <table>
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="quanxuan"/></th>
                                    <th>配包流水</th>
                                    <th>网篮条码</th>
                                    <th>包条码</th>
                                    <th>包名称</th>
                                    <th>配包人</th>
                                    <th>配包时间</th>
                                    <th>审核状态</th>

                                </tr>
                                </thead>
                                <tbody id="dayinAll" class="packagedetail">
                                <c:if test="${peibaoList != null}">
                                    <!-- var 是给给他起名字 -->
                                    <c:forEach items="${peibaoList}" var="peibaoList">
                                        <tr data="${peibaoList.qingxiLiushui}" class="qingxidata">
                                            <td><input type="checkbox" name="key"/></td>
                                            <td>${peibaoList.peibaoLiushui }<input type="hidden" name="peibaoLiushui"
                                                                                   value="${peibaoList.peibaoLiushui }">
                                            </td>
                                            <td>${peibaoList.qingxiWanglanTiaoma}<input type="hidden" name="packageId" value="${peibaoList.qingxiLiushui}"/></td>
                                            <td>${peibaoList.peibaoBaozhuangTiaoma}<input type="hidden"
                                                                                          name="peibaoBaozhuangTiaoma"
                                                                                          value="${peibaoList.peibaoBaozhuangTiaoma }">
                                            </td>
                                            <td>${peibaoList.qingxiWupinbaoMingcheng}</td>
                                            <td>${emMap[peibaoList.peibaoPiebaorenTiaoma]}</td>
                                            <td><fmt:formatDate value="${peibaoList.peibaoTime}"

                                                                type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                            <td>
                                                <select name="peibaoHege">
                                                    <option value="1">关包完成</option>
                                                </select>
                                            </td>

                                        </tr>
                                    </c:forEach>
                                </c:if>


                                </tbody>
                            </table>
                            <div id="kkpager"></div>
                            <div class="kv-item clearfix">
                                <p>
                                    <span>关包人  :</span>
                                    <input type="text" id="guanbaoTiaoma" name="guanbaoTiaoma" placeholder="关包人"
                                           onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                                </p>

                            </div>
                            <a href="javascript:;" class="sapar-btn sapar-btn-recom" id="baocun">保存</a>


                        </div>
                    </form>
                </div><!--表格结束-->

            </div>
        </div>
        <div id="saper-ft">

        </div>
    </div>

</div>
<script type="text/javascript">
    window.onload = function () {
        $("input[name='guanbaoTiaoma']").focus();
    };

    $(function () {
        var totalPage = ${total};
        var pageNo = getParameter('pageIndex');
        if (!pageNo) {
            pageNo = 1;
        }
        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno: pageNo,
            //总页码
            total: totalPage,
            //链接前部
            hrefFormer: '${ctx}/peibao/guanbaoList',
            //链接尾部
            hrefLatter: '.do',
            getLink: function (n) {
                return this.hrefFormer + this.hrefLatter + "?pageIndex=" + n + "&searchTxt=" + $(".search_text").val();
            }
        });

        $("#quanxuan").live("click", function () {
            var that = $(this);
            var flag = true;
            if(that.prop('checked')){
                flag = true;
            }else{
                flag = false;
            }
            $(".packagedetail").find("input[name='key']").each(function () {
                ck = $(this);
                if (flag) {
                    ck.prop('checked', true);
                } else {
                    ck.prop('checked', false);
                }
            });
        })


        $("#baocun").click(function () {
            var ck = getSelRecord2();
            var ok = true;
            if (ck.length == 0) {
                ok = false;
                alert("没有选中关包");
            }
            ck = JSON.stringify(ck);
            var person = $("#guanbaoTiaoma").val();
            var pdata = {"peoplecode":person,"datas":ck};
            pdata = JSON.stringify(pdata);
            if(ok){
                $.ajax({
                    type: "post",
                    url: "${ctx}/peibao/guanbaoBaocun.do?",
                    error: function () {
                        layer.alert("网络故障，稍后再试");
                    },
//                data: $("#guanbaoform").serialize(),
                    data: {"pdata": pdata},
                    success: function (data) {
                        if (data.status == "true") {
                            console.log(data);
                            var json = getSelRecord();
                            console.log(json);
                            for (var i = 0; i < json.length; i++) {
                                console.log(json.length)
                                var huishouWupinbaoTiaoma = json[i].packageTiaoma;
                                var baoName = json[i].packageName;
                                var huishouWupinbaoMuban = json[i].packId;
//                            dayin(huishouWupinbaoTiaoma, baoName, huishouWupinbaoMuban);
                            }
                            window.location.reload();
                        } else {
                            layer.msg(data.msg);
                            $("input[name='guanbaoTiaoma']").val("");
                        }
                    }
                })
            }

        });

        $(document).keydown(function (event) {
            var oPlay0 = document.getElementById("audio");
            var oPlay1 = document.getElementById("audio1");
            var guanbaoTiaoma = $("input[name='guanbaoTiaoma']").val();
            if (event.keyCode == 13) {
                if ($("#guanbaoTiaoma").is(":focus") && !isNullOrEmpty(guanbaoTiaoma)) {
                    $("#baocun").click();
                }
            }
        });


    });

    var LODOP;
    function myPrint() {
        CreatePrintPage();
        LODOP.PRINT();
    };
    function myPrintA() {
        CreatePrintPage();
        LODOP.PRINTA();
    };

    function myPreview() {
        CreatePrintPage();
        LODOP.PREVIEW();
    };
    function mySetup() {
        CreatePrintPage();
        LODOP.PRINT_SETUP();
    };
    function myDesign() {
        CreatePrintPage();
        LODOP.PRINT_DESIGN();
    };
    function myBlankDesign() {
        LODOP = getLodop();
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_空白练习");
        LODOP.PRINT_DESIGN();
    };

    function CreatePrintPage(packImfor) {

        console.log(packImfor[3]);
        var miejuntime = packImfor[6];
        var baoName = packImfor[3];
        var depName = packImfor[2];
        var guoqitime = packImfor[7];
        var days = packImfor[8];
        var baoTiaoma = packImfor[4];
        var queshi = packImfor[0];
        var peibaoren = packImfor[1];
        var shenheRen = packImfor[9];
        var guanbaoRen = packImfor[10];
        console.log(baoName);
        LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_名片");
        LODOP.ADD_PRINT_RECT(10, 10, 256, 142, 0, 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.SET_PRINT_STYLE("FontName", "微软雅黑");
        LODOP.ADD_PRINT_TEXT(10, 10, 170, 38, baoName);
        LODOP.ADD_PRINT_TEXT(16, 160, 80, 38, depName);
        LODOP.ADD_PRINT_RECT(38, 10, 256, 116, 0, 1);
        LODOP.ADD_PRINT_RECT(85, 10, 256, 116, 0, 1);
        LODOP.ADD_PRINT_TEXT(40, 10, 150, 38, "灭菌日期：" + miejuntime);
        LODOP.ADD_PRINT_TEXT(70, 10, 150, 38, "失效日期：" + guoqitime + "(" + days + ")天");
        LODOP.ADD_PRINT_TEXT(40, 160, 150, 19, "配包人：" + peibaoren);
        LODOP.ADD_PRINT_TEXT(55, 160, 150, 19, "审核人："+shenheRen);
        LODOP.ADD_PRINT_TEXT(70, 160, 150, 19, "打包人："+guanbaoRen);
        LODOP.SET_PRINT_STYLEA(2, "FontName", "隶书");
        LODOP.SET_PRINT_STYLEA(2, "FontSize", 14);
        LODOP.SET_PRINT_STYLEA(3, "FontSize", 11);
        LODOP.ADD_PRINT_TEXT(98, 10, 150, 19, "条码");
        LODOP.ADD_PRINT_BARCODE(90, 50, 200, 25, "Code39", baoTiaoma);
        //LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
        LODOP.ADD_PRINT_TEXT(125, 10, 150, 19, "条码");
        LODOP.ADD_PRINT_BARCODE(120, 50, 200, 30, "Code39", baoTiaoma);
        //LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
        //LODOP.PREVIEW();
        LODOP.PRINT();
    };

    function dayin(huishouWupinbaoTiaoma, baoName, huishouWupinbaoMuban) {
        $.get('${ctx}/peibao/tiaoma.do?huishouWupinbaoTiaoma=' + huishouWupinbaoTiaoma + "&huishouWupinbaoMuban=" + huishouWupinbaoMuban, function (data) {
            console.log(data);
            CreatePrintPage(data.packImfor);
        })
    }

    function getSelRecord() {
        var chk_value = [];
        $("#dayinAll").find("tr").each(function () {
            var tdArr = $(this).children();
            var packId = tdArr.eq(1).find("input").val()
            var packageTiaoma = tdArr.eq(2).text();
            var packageName = tdArr.eq(3).text();
            var json = {
                "packId": packId,
                "packageTiaoma": packageTiaoma,
                "packageName": packageName,
            };

            chk_value.push(json);
        });
        return chk_value;
    }

    function getSelRecord2() {
        debugger
        var chk_value = [];
        $('input[name="key"]:checked').each(function () {
            var state = $(this).parent().parent().find("select[name=peibaoHege]").val();
            var peibaoLiushui = $(this).parent().parent().find("input[name=peibaoLiushui]").val();
            var peibaoBaozhuangTiaoma = $(this).parent().parent().find("input[name=peibaoBaozhuangTiaoma]").val();
            var json = {"state": state, "peibaoLiushui": peibaoLiushui, "peibaoBaozhuangTiaoma": peibaoBaozhuangTiaoma};
            chk_value.push(json);
        });
        return chk_value;
    }

    function isNullOrEmpty(strVal) {
        if (strVal != null) {
            strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        }
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }
    function getParameter(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
</script>
</body>
</html>